<template>
  <div class="contentTable" v-loading="loading">
    <div class="contentTableTop">
      <div class="contentTableTitle">岗位</div>
    </div>
    <div class="positionList-box" v-if="positionList.length">
      <el-scrollbar style="height: 100%">
        <div v-for="item in positionList" :key="item.positionId" class="item" @mouseenter="handleMouseFloat(item)"
          @mouseleave="handleMouseFloat(item)">
          <div class="item-info">
            <div class="item-info-text">
              <div class="item-info-text-left" @click="toJobDetail(item)">
                <div class="item-info-text-left-name">
                  {{ item.jtzw || '' }}
                </div>
                <div class="item-info-text-left-salary">
                  <div class="salary">{{ item.xzdy_new }}</div>
                  <div class="command-box">
                    <span class="command line" v-if="item.regionname">{{
                      item.regionname
                    }}</span>
                    <span class="command line" v-if="item.edus">{{
                      item.edus
                    }}</span>
                    <span class="command" v-if="item.gznum">{{
                      item.gznum
                    }}</span>
                  </div>
                </div>
              </div>
              <div class="item-info-text-middle">
                <div class="item-info-text-middle-logo">
                  <img class="logo" :src="item.logo" />
                </div>
                <div class="item-info-text-middle-info">
                  <div class="name">{{ item.cname_all }}</div>
                  <div class="command-box">
                    <span class="command line" v-if="item.yuangong">{{
                      item.yuangong
                    }}</span>
                    <span v-if="item.fldy && item.fldy.length">
                      <span v-for="(v, index) in item.fldy" :class="[
                          'command',
                          index < item.fldy.length - 1 ? 'line' : ''
                        ]" :key="index">{{ v }}</span>
                    </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="item-info-btn">
              <div class="btn-box" v-show="item.showBtn">
                <el-popover popper-class="qr-code-popover" placement="bottom-end" width="180" trigger="hover"
                  @show="handleShowQrCode(item)">
                  <div class="qr-code-box" v-loading="imgLoading">
                    <img :src="communicateQRCode" class="qr-code" />
                    <span>扫码快速沟通投递</span>
                  </div>
                  <div class="normal" slot="reference">投简历</div>
                </el-popover>
                <div class="plain" @click.stop="handleCancelCollect(item)">
                  取消收藏
                </div>
              </div>
            </div>
          </div>
          <div class="item-contact">
            <div class="item-contact-info" v-if="item.personJobInfo">
              <img class="avatar" :src="item.personJobInfo.pic" />
              <span class="text">{{ item.personJobInfo.iname }} · </span>
              <span class="text">{{ item.personJobInfo.pnames }}</span>
              <span class="text time">{{ item.personJobInfo.activeTime }}</span>
            </div>
            <div class="item-contact-desc text spot">
              {{ item.address }}
            </div>
            <div class="item-contact-desc text task">
              {{ item.zptxt }}
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <el-empty class="empty" description="暂无收藏内容" v-else></el-empty>
    <div class="pager" v-show="pData.total > 0">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="pData.currentPage" :page-sizes="pData.pageSizes" :page-size="pData.pageSize"
        :layout="pData.layout" :total="pData.total" background></el-pagination>
    </div>
  </div>
</template>

<script>
import { createQROther } from "@/api/home.js";
import { getCollectionJobs, collectJob } from "@/api/job-detail";
import avatar from "@/assets/images/png/avatar_default.png";
import pagination from "@/mixin/pagination";
export default {
  name: "careerTable",
  mixins: [pagination],
  components: {},
  data() {
    return {
      avatar,
      positionList: [],
      loading: false,
      imgLoading: false,
      communicateQRCode: "",
    };
  },
  created() {
    this.getData();
  },
  methods: {
    async handleShowQrCode(item) {
      this.imgLoading = true;
      const params = {
        path: "pagesSub/public/jobDetail/index",
        scene: `zp_id=${item.id}`, // TODO:
      };
      const res = await createQROther(params);
      this.imgLoading = false;
      if (res.code == 200) {
        this.communicateQRCode = res.data;
      }
    },
    handleCancelCollect(item) {
      this.$confirm("确定取消收藏吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.handleCollection(item);
        })
        .catch(() => {});
    },
    handleCollection(item) {
      const params = {
        dataId: item.id, // TODO:
        dataType: "10",
        action: "0", // 1 收藏 0 取消收藏
      };
      collectJob(params).then((res) => {
        if (res.code == 200) {
          this.$message.success("已取消收藏");
          this.getData();
        } else {
          this.$message.error("取消收藏失败");
        }
      });
    },
    toJobDetail(item) {
      let routeData = this.$router.resolve({
        path: `/job-detail?companyId=${item.uid}&zp_id=${item.id}`,
      });
      window.open(routeData.href, "_blank");
    },
    handleMouseFloat(item) {
      item.showBtn = !item.showBtn;
    },
    getData() {
      this.loading = true;
      const params = {
        pageNo: this.pData.currentPage,
        pageSize: this.pData.pageSize,
      };
      getCollectionJobs(params)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((item) => {
              item.showBtn = false;
            });
            this.positionList = res.data;
            this.pData.total = res.pageparam.sums;
          } else {
            console.log(res);
          }
        })
        .catch((e) => {
          console.log(e);
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.qr-code-popover {
  .qr-code-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: #333333;
    .qr-code {
      width: 148px;
      height: 148px;
      margin-bottom: 14px;
    }
  }
}
.contentTable {
  flex: 1;
  padding: 24px 0 24px 0;
  .contentTableTop {
    display: flex;
    align-items: center;
    padding-left: 24px;
    .contentTableTitle {
      font-family: PingFang-SC, PingFang-SC;
      font-weight: bold;
      font-size: 20px;
      color: #333333;
      line-height: 20px;
      text-align: left;
      font-style: normal;
      margin-right: 32px;
    }
  }
  .positionList-box {
    // height: 72vh;
    height: calc(100vh - 260px);
    .item {
      margin: 0 24px 15px 24px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #e4e5e7;
      &:first-child {
        margin-top: 15px;
      }
      .command-box {
        display: flex;
        align-items: center;
        .command {
          font-family: PingFangSC, PingFang SC;
          font-size: 13px;
          color: #a2a5b3;
          padding: 0 11px;
        }
        .line {
          position: relative;
          &:after {
            content: "";
            position: absolute;
            top: 50%;
            right: 0;
            width: 1px;
            height: 11px;
            background: #e5e6eb;
            transform: translateY(-50%);
          }
        }
      }
      &:last-child {
        margin-bottom: 16px;
      }
      &:hover {
        box-shadow: 0px 2px 15px 4px rgba(73, 159, 217, 0.25);
      }
      &-info {
        display: flex;
        padding: 16px 14px;
        &-text {
          flex: 1;
          display: flex;

          &-left {
            width: 340px;
            cursor: pointer;
            &-name {
              font-weight: bold;
              font-size: 16px;
              color: #222222;
              margin-bottom: 18px;
            }
            &-salary {
              display: flex;
              .salary {
                font-weight: bold;
                font-size: 16px;
                color: #d5413d;
                margin-right: 14px;
              }
            }
          }
          &-middle {
            margin-left: 100px;
            display: flex;
            align-items: center;
            &-logo {
              width: 48px;
              height: 48px;
              padding: 3px;
              background: #ffffff;
              border-radius: 2px;
              border: 1px solid #e1e4ed;
              margin-right: 25px;
              display: flex;
              justify-content: center;
              align-items: center;
              .logo {
                width: 40px;
                height: auto;
              }
            }
            &-info {
              .name {
                margin-bottom: 18px;
                font-weight: bolder;
                font-size: 16px;
                color: #222222;
              }
            }
          }
        }

        &-btn {
          width: 320px;
          display: flex;
          justify-content: flex-end;
          .btn-box {
            display: flex;
          }
          .normal {
            font-family: PingFang-SC, PingFang-SC;
            // font-weight: bold;
            font-size: 16px;
            color: #ffffff;
            width: 140px;
            text-align: center;
            border-radius: 8px;
            background: #4880ff;
            margin-right: 12px;
            height: 36px;
            line-height: 36px;
            cursor: pointer;
          }
          .plain {
            font-family: PingFang-SC, PingFang-SC;
            // font-weight: bold;
            font-size: 16px;
            width: 104px;
            text-align: center;
            height: 36px;
            line-height: 36px;
            color: #4880ff;
            padding: 0 19px;
            border-radius: 8px;
            background: #fff;
            border: 1px solid #4880ff;
            cursor: pointer;
          }
        }
      }
      &-contact {
        display: flex;
        align-items: center;
        padding: 11px 16px;
        background: linear-gradient(
          276deg,
          rgba(218, 240, 247, 0.1) 0%,
          rgba(230, 240, 255, 0.3) 100%
        );
        &-info {
          display: flex;
          align-items: center;
          flex-grow: 0;
          .avatar {
            width: 25px;
            height: 25px;
            border: 2px solid #ffffff;
            border-radius: 50%;
            margin-right: 8px;
          }
          .time {
            margin-left: 8px;
          }
        }
        .text {
          font-family: PingFangSC, PingFang SC;
          font-size: 14px;
          color: #9cabb7;
        }
        .spot {
          margin-left: 69px;
          flex-grow: 0;
        }
        .task {
          margin-left: 72px;
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 0; // 一定要设置,不然会导致文字溢出
        }
      }
    }
  }
  .pager {
    display: flex;
    justify-content: flex-end;
  }

  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #0b6eff;
  }

  @media (min-width: 576px) {
    .col-sm-2a {
      grid-template-columns: repeat(auto-fill, minmax(33%, 1fr));
    }
  }
  @media (min-width: 995px) {
    .col-lg-3a {
      grid-template-columns: repeat(auto-fill, minmax(25%, 1fr));
    }
  }
  @media (min-width: 1300px) {
    .col-lg-3a {
      grid-template-columns: repeat(auto-fill, minmax(20%, 1fr));
    }
  }
  @media (min-width: 1500px) {
    .col-xl-5a {
      grid-template-columns: repeat(auto-fill, minmax(18%, 1fr));
    }
  }
  @media (min-width: 1800px) {
    .col-xxl-6a {
      grid-template-columns: repeat(auto-fill, minmax(14.6%, 1fr));
    }
  }
  @media (min-width: 2200px) {
    .col-xxxl-7a {
      grid-template-columns: repeat(auto-fill, minmax(11%, 1fr));
    }
  }
  @media (min-width: 2600px) {
    .col-xxxxl-8a {
      grid-template-columns: repeat(auto-fill, minmax(10%, 1fr));
    }
  }
}
</style>
